<?php
	header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

	// Includes
	require_once $_SERVER['DOCUMENT_ROOT'] . '/../include/apps/janus/includes.php';
	
	

	// Create our Application instance
	$facebook = new Facebook(array(
		'appId'  => $GLOBALS['FACEBOOK']['ID'],
		'secret' => $GLOBALS['FACEBOOK']['SECRET'],
		'cookie' => true,
		'domain' => 'leedsmet.ac.uk'
	));
	
	// Ensure there is a session for this user and the app has been granted basic permissions
	//$session = JanusFacebook::checkSessionAuth($facebook);
	$session = $facebook->getSession();
	$facebook_id = $facebook->getUser();
	
	if ($session)
	{
		try
		{
			$application = $facebook->api($GLOBALS['FACEBOOK']['ID']);
			$appName     = htmlspecialchars($application['name']);
		}
		catch (FacebookApiException $e)
		{
			error_log($e);
			$appName = $GLOBALS['BRANDING']['FULL_NAME'];
		}
	}
	

	// Load tabs template. By default, detected replacement codes are replaced with an empty 
	// string so only those that are specified will be replaced with something useful. 
	$template = new MarkupTemplate();
	$template->loadTemplateFile($GLOBALS['TEMPLATES']['BASE_PATH'] . 'fb_tabs.tpl', true);
	$template->updateReplacement('ABOUT_TAB_SELECTED', 'selected', false);
	$tabContent = $template->getOutputMarkup();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" href="/main/apps/janus/css/janus.css" type="text/css" />
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
/* <![CDATA */
	window.fbAsyncInit = function() {
		FB.init({
			appId   : '<?php echo $facebook->getAppId(); ?>',
			session : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it
			status  : true, // check login status
			cookie  : true, // enable cookies to allow the server to access the session
			xfbml   : true // parse XFBML
		});

		// whenever the user logs in, we refresh the page
		FB.Event.subscribe('auth.login', function() {
			window.location.reload();
		});

		// Parse any FBML
		//FB.XFBML.parse();
	};
	
	(function() {
		var e = document.createElement('script');
		e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
		e.async = true;
		document.getElementById('fb-root').appendChild(e);
	}());
/* ]]> */
</script>
<h1><?php echo $appName; ?></h1>
<?php echo $tabContent; ?>
<?php //echo $pageContent; ?>
<h2>About this App</h2>
<p>Something about this app.</p>
<p>You need to accept the request for permissions to use the app.</p>
<p>Click on 'My Account' to do this.</p>
</body>
</html>